import {login} from '../../api/index.js'

Page({
  data: {
    username: 'yonghu',
    password: '12345'
  },
  
  // 用户名输入处理
  usernameInput: function(e) {
    this.setData({
      username: e.detail.value
    });
  },
  
  // 密码输入处理  
  passwordInput: function(e) {
    this.setData({
      password: e.detail.value
    });
  },
  
  async  login() {
    const res = await login({
      username: this.data.username,
      password: this.data.password
    })
    if (res.code === 200) {
      wx.setStorageSync('token', res.token)
      wx.reLaunch({
        url: '/pages/index/index'
      })
    }
    wx.login({
      success: res => {
        wx.reLaunch({
          url: '/pages/index/index'
        })
      }
    })
  }
})